<?php

use Biz\pockets\constInterface\SourceRightsInterface;
use Biz\service\BrandRights\BrandLevelRightsService;

class LevelRightsAction extends ActionPlugin
{

    const USER_LEVEL = self::LEVEL_REGISTER;

    public function main()
    {
        $isH5 = $this->getPost('is_h5', 0);

        $brandInfo = [];
        $returnData = [
            'count' => 0,
            'more_link' => BrandLevelRightsService::getMoreLink(),
            'list' => [],
        ];

        $iconType = $isH5 ? SourceRightsInterface::ICON_TYPE_H5 : SourceRightsInterface::ICON_TYPE_APP;

        $rights = BrandLevelRightsService::getBrandLevelRightsStateByUid($this->uid, $iconType);
        if ($rights) {
            [$brandInfo, $returnData['count'], $returnData['list']] = $rights;
        }

        $extend = '';

        if (!empty($brandInfo) && in_array($this->appType, [self::APPTYPE_IOS, self::APPTYPE_ANDROID])) {
            $extend = BrandLevelRightsService::getLevelAlertExtend($brandInfo['id'], $brandInfo['level']);
        }

        $this->setSuccess($returnData, self::API_CODE_SUCCES, $extend);
    }


}